<?php

namespace app\modules\user\service;

use Yii;
use app\common\behaviors\ApiCommonBehavior;
use app\common\base\ApiService;
use app\modules\user\models\Comment;
use DateTime;
use Exception;
use PhpOffice\PhpSpreadsheet\Shared\Date;

class CommentService extends ApiService
{
    function __construct()
    {
        parent::init();
        $this->model = new Comment();
    }

    /**
     * 添加评论;
     */
    public function addComment($comment, $filmId, $userId){
        $init = [
            'status' => 1,
            'comment' => $comment,
            'film_id' => $filmId,
            'user_account_id' => $userId,
        ];

        $res = $this->add($init);

        return ($res != null);
    }

    /**
     * 删除评论;
     */
    public function DeleteComment($commentId, $userId){
        $info = $this->info([
            'condition' => [
                'id' => $commentId,
            'status' => 1,
            'user_account_id' => $userId
            ]    
        ]);
        if(empty($info)){
            return ApiCommonBehavior::error('ERROR_EXECUTE_FAILED', '操作失败');
        }

        $res = $this->update([
            'id' => $commentId,
            'status' => 0,
            'user_account_id' => $userId
        ]);

        return true;
    }

}

